<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>APP</title>
    <link rel="stylesheet" type="text/css" href="../assets/css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../assets/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../assets/css/loaders.css"/>
</head>

<body>
<div id="wrap" class="scan">

</div>
</body>
<script type="text/javascript" src="../assets/js/api.js"></script>
<script type="text/javascript" src="../assets/js/common.js"></script>
<script type="text/javascript">


    apiready = function () {

        var pageParam = api.pageParam || {};
        var headers = pageParam.header || {};

        var FNScanner = api.require('FNScanner');

        FNScanner.openView({
            autorotation: true,
            rect        : {x: 0, y: 0, w: api.winWidth, h: api.winHeight}
        }, function (ret) {
            if (ret.eventType === 'success') {
                var url = ret.content || '';
                if (url.indexOf('/app/preorder.html') > 1) {
                    url = url.replace('/app/preorder.html', '/app/preapp.html');

                    jsApi.openScanWindow(url, headers);

                } else {
                    jsFn.alert('二维码有误');
                }
            } else if (ret.eventType === 'cameraError') {
                jsFn.alert('二维码有误');
            } else if (ret.eventType === 'albumError') {
                jsFn.alert('访问相册失败');
            } else if (ret.eventType === 'fail') {
                jsFn.alert('扫码失败');
            }

            jsApi.closeWindow();
        });

        api.addEventListener({name: 'resume'}, function (ret, err) {
            FNScanner.onResume();// alert('应用回到前台');
        });

        api.addEventListener({name: 'pause'}, function (ret, err) {
            FNScanner.onPause();// alert('应用进入后台');
        });


        var frameOption = {
            name: jsFn.frameName,
            url : '../html/scan_view.html',
            // bounces     : true,
            // useWKWebView: true,
            rect: {marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0}
        };
        api.openFrame(frameOption);

    };

</script>

</html>
